package com.gdkm.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.gdkm.po.Page;
import com.gdkm.po.Student;
import com.gdkm.po.User;

@Repository
@Mapper
public interface UserDao {
//	    增加
	@Insert("insert into tb_user(user_code,user_name,user_password,user_state) "
			+ "values(#{user_code},#{user_name},#{user_password},#{user_state})")
	void save(String user_code, String user_name, String user_password, String user_state);

	// 查询一个
	@Select("SELECT * FROM tb_user where user_code=#{user_code}")
	User get(String user_code);

	// 查询全部
	@Select("SELECT * FROM tb_user where user_code=#{user_code}")
	List<User> gettest(String user_code);

//	    修改
	@Update("UPDATE  user_management set usercode=#{usercode},password=#{password},name=#{name}"
			+ ",age=#{age},grade=#{grade},phoneNumber=#{phoneNumber},sex=#{sex}" + ",type=#{type} where id=#{id}")
	void update(Student stu);

//	    模糊查询
	@Select("SELECT * FROM user_management WHERE name LIKE concat('%',#{name},'%') && grade LIKE concat('%',#{grade},'%') && type LIKE concat('%',#{type},'%')limit #{y},#{ge}")
	List<Student> list(String name, String grade, String type, int y, int ge);

	@Insert("INSERT INTO user_management(usercode,password,name,age,grade,phoneNumber,sex,type) values(#{usercode},#{password},#{name},#{age},#{grade},#{phoneNumber},#{sex},#{type})")
	void save1(String usercode, String password, String name, String age, String grade, String phoneNumber, String sex,
			String type);

	// 删除
	@Delete("DELETE FROM user_management where id=#{id}")
	void delete1(int id);

	// 分页查询
	@Select("SELECT * FROM user_management  limit #{y},#{ge}")
	List<Student> list1(int y, int ge);

	@Select("SELECT * FROM user_management where usercode=#{usercode}")
	Student get1(String usercode);

	@Insert("insert into user_management(usercode,password,name) values(#{usercode},#{password},#{name})")
	void save2(String usercode, String password,String name);

	@Select("SELECT * FROM user_management where usercode=#{usercode}")
	List<Student> list8(String usercode);
	
	@Select("select * from user_management where usercode=#{usercode}")
	Student findByUsercode(String usercode);
}
